//
//  CFMarketDetailVC.m
//  CFfuturestalent
//
//  Created by 子yu 刘 on 2018/5/4.
//  Copyright © 2018年 子yu 刘. All rights reserved.
//

#import "CFMarketDetailVC.h"
#import "CFSheetView.h"
#import "CFTimeQuartzView.h"

@interface CFMarketDetailVC ()

@property (nonatomic,strong)CFTimeQuartzView * TimeQuartzView;

@end

@implementation CFMarketDetailVC{
    UIButton * _lastBtn;
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [AFMarketNetData manager].detaileDataDelegate = self;
    excode = @"WGJS";
    code_code = @"XAU";
   // [self initquartzTimeView];
    [self getTimedata];

}

- (void)getTimedata{
 [[AFMarketNetData manager] timeDataLoadWithExcode:excode code:code_code withHost:HTmmarket];
}


/**
展开行情更多详情
 */
- (IBAction)unfold:(UIButton *)sender {
    [sender setSelected:!sender.isSelected];
    if (sender.isSelected) {
        [sender setImage:DEF_IMAGENAME(@"上") forState:UIControlStateNormal];
        self.moreView.hidden = NO;
    }else{
          [sender setImage:DEF_IMAGENAME(@"下") forState:UIControlStateNormal];
        self.moreView.hidden = YES;
    }
}

/**
 切换k线类型
 */
- (IBAction)switchKLine:(UIButton *)sender {
    if (_lastBtn) {
        [_lastBtn setTitleColor:DEF_COLOR_HEX_687278 forState:UIControlStateNormal];
        if (_lastBtn.tag == 103) {
            [_lastBtn setTitle:@"多周期" forState:UIControlStateNormal];
        }
    }
    if (sender.tag<104) {
        if (sender.tag<103) {
            [UIView animateWithDuration:0.3 animations:^{
                self.line.centerX = sender.centerX;
                [sender setTitleColor:DEF_COLOR_RED forState:UIControlStateNormal];
            }];
        }else{
            NSArray * titleArray = @[@"1分钟",@"5分钟",@"15分钟",@"60分钟",@"240分钟",@"周线",@"月线",@"年线"];
            [CFSheetView sheetViewWithTitleArray:titleArray index:^(NSInteger index) {
                [sender setTitleColor:DEF_COLOR_RED forState:UIControlStateNormal];
                [sender setTitle:titleArray[index] forState:UIControlStateNormal];
                 self.line.centerX = sender.centerX;
            }];
        }

    }
    _lastBtn = sender;
}

-(CFTimeQuartzView *)TimeQuartzView{
    if (!_TimeQuartzView) {
        _TimeQuartzView = [[CFTimeQuartzView alloc] initWithFrame:self.kLineView.bounds];
        [self.kLineView addSubview:_TimeQuartzView];
    }
    return _TimeQuartzView;
}
//
//- (void)initquartzTimeView{
//    self.quartzTimeView = [[AFTimeQuartzView alloc] initWithFrame:CGRectZero];
//    //self.quartzTimeView.frame = self.kLineView.bounds;
//    [self.kLineView addSubview:self.quartzTimeView];
//    [self.quartzTimeView mas_makeConstraints:^(MASConstraintMaker *make) {
//        make.edges.mas_equalTo(0);
//    }];
//
//}
//
-(void)marketTimeDataLoadEnd{
    [self marketTimeViewRefresh];
}

-(void) marketTimeViewRefresh{
    [self.TimeQuartzView reloadData];
}



@end
